﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>填充主表</title>
    <link href="../../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script src="../../../Scripts/easyUI145/jquery.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/easyUI145/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../../Comm/Gener.js" type="text/javascript"></script>
    <script src="DDLBar.js" type="text/javascript"></script>
    <script src="../../CCFlowEnum.js" type="text/javascript"></script>
    <script src="../../Admin.js"></script>
    <!--<script src="../../../Scripts/LoadSql.js"></script>-->
    <script type="text/javascript">
        var extType = "";

        $(function () {

            extType = GetQueryString("ExtType");
            extType = extType == null || extType == undefined ? "" : extType;

            InitBar("Main");

            //查询出来数据.
            var frmID = GetQueryString("FK_MapData");


            var refPK = GetQueryString("RefPK");

            var thisPK = refPK + "_FullData";

            if (extType == "PageLoadFull") {
                //确定后执行的函数需要隐藏
                $("#okBack1").hide();
                $("#okBack2").hide();

                //只能SQL填充数据源
                $("select[name='DDL_DBType'] option[value='1']").remove();
                $("select[name='DDL_DBType'] option[value='2']").remove();

                thisPK = refPK;
            }

            //显示字段.
            ShowFrmFields();


            var en = new Entity("BP.Sys.MapExt");
            en.MyPK = thisPK;
            en.SetPKVal(thisPK);
            en.RetrieveFromDBSources();


            //绑定数据源类型. 在填充的时候，设置数据源.
            var ens = new Entities("BP.Sys.SFDBSrcs");
            ens.RetrieveAll();
            GenerBindDDL("DDL_FK_DBSrc", ens, "No", "Name", en.FK_DBSrc);

            en.Doc = FormatSQL(en.Doc);

            //给下列框赋值.
            GenerFullAllCtrlsVal(en);

            $("#TB_SQL").val(en.Doc);


            DBTypeChange();
            var requestMethod = en.GetPara("RequestMethod", "Get");
            $("#DDL_RequestMethod").val(requestMethod);
            var postContent = en.GetPara("PostContent", "");
            postContent = postContent.replace(/~/g, "'").replace(/'/g, "\"");
            $("#TB_Post").val(postContent)
        });

        function Save() {

            //更新节点表单类型.
            var frmID = GetQueryString("FK_MapData");
            var refPK = GetQueryString("RefPK");

            var thisPK = refPK + "_FullData";
            if (extType == "PageLoadFull")
                thisPK = refPK;

            var en = new Entity("BP.Sys.MapExt");
            en.MyPK = thisPK;
            en.SetPKVal(en.MyPK);
            var i = en.RetrieveFromDBSources();
            en.SetPara("RequestMethod",$("#DDL_RequestMethod").val());

            en.FK_MapData = frmID;
            if (extType != "PageLoadFull") {
                en.ExtType = "FullData"; //.通用的.
                en.AttrOfOper = GetQueryString("KeyOfEn");
            }
            else {
                en.ExtType = "PageLoadFull";
                en.AttrOfOper = "";
            }

            en.DBType = $("#DDL_DBType").val(); //获得选择的值.
            en.FK_DBSrc = $("#DDL_FK_DBSrc").val(); //获得选择的值.

            var sql = $("#TB_SQL").val();
            if (sql == '') {
                alert("填充主表的sql不能为空！");
                return;
            }

            //按钮的操作的时候不判断语句是否有@Key
            var keyControlType = GetQueryString("UIControlType") || "";
            if (!(en.DBType == 1 && en.Tag3 == 'Post')) {
                //方便填充主表字段 只判断@
                if (sql.indexOf('@') == -1 && extType != "PageLoadFull") {
                    alert("表达式里必须有 @Key 参数.");
                    return;
                }
            }


            en.Doc = sql; //设置主表的SQL.
            var tag2 = $("#TB_Tag2").val();
            en.Tag2 = tag2; //设置主表的SQL.


            var postContent = $("#TB_Post").val();
            postContent = postContent.replace(/"/g, "'").replace(/'/g, "~");
            en.SetPara("PostContent", postContent);

            if (i == 0)
                en.Insert();
            else
                en.Update();

            Reload();
        }
        function EtcDBFull() {
            var url = GetHrefUrl();
            url = url.replace("Main.htm", "MainDtlList.htm");
            SetHref(url);
        }
    </script>
</head>
<body>
    <form id="cc">
        <div id="bar">
        </div>
        <table style="width: 99%;">
            <tr>
                <td>数据源类型</td>
                <td>
                    <select id="DDL_DBType" name="DDL_DBType" onchange="DBTypeChange(this)">
                        <option value="0">执行SQL</option>
                        <option value="1">执行url返回JSON</option>
                        <option value="2">执行CCFromRef.js返回JSON</option>
                    </select>
                </td>
            </tr>
            <tr id="DBSrc">
                <td> 数据源</td>
                <td>
                    <select id="DDL_FK_DBSrc" name="DDL_FK_DBSrc">
                    </select>
                </td>
            </tr>
            <tr id="RequestMethod">
                <td> 请求模式</td>
                <td>
                    <select id="DDL_RequestMethod" name="DDL_RequestMethod">
                        <option value="Get">GET</option>
                        <option value="Post">POST</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    填充主表数据数据源表达式(SQL/URL)
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <textarea rows="4" name="TB_SQL" id="TB_SQL" style="width: 98%;"> </textarea>
                </td>
            </tr>
            <tr class="Post">
                <td colspan="2">
                    POST请求参数
                </td>
            </tr>
            <tr class="Post">
                <td colspan="2">
                    <textarea rows="4" name="TB_Post" id="TB_Post" style="width: 98%;"> </textarea>
                </td>
            </tr>

            <tr id="okBack1">
                <td colspan="4">
                    <a href="javascript:ShowHidden('backFunction')">确定后执行的JS</a>,可以为空.
                    <div id="backFunction" style="color: Gray; display: none">
                        <ul>
                            <li>该选项可以为空,弹出框确定后执行的JS，可以直接写方法名或者方法().</li>
                        </ul>
                    </div>
                </td>
            </tr>
            <tr id="okBack2">
                <td colspan="4">
                    <input type="text" id="TB_Tag2" name="TB_Tag2" style="width: 99%;" />
                </td>
            </tr>
        </table>

        <br />

        <fieldset>
            <legend>SQL填写帮助.</legend>
            <ul>
                <li>必须返回一行数据的 SQL或者数据源. </li>
                <li>返回的列名要与字段名进行对应，如果匹配的不管控件类型系统就会自动赋值.</li>
                <li>
                    实例： <font color="green">
                        SELECT  Name as MingCheng, Tel as DianHua, Email FROM WF_EMP WHERE No='@Key'
                    </font>
                </li>
                <li> @Key 就是指选择的主键. 是系统约定的标记. </li>
            </ul>

            <legend>URL填写帮助.</legend>
            <ul>
                <li>必须返回一行数据的的json格式的数据源. </li>
                <li>返回的列名要与字段名进行对应，如果匹配的不管控件类型系统就会自动赋值.</li>
                <li>实例：  <font color="green"> /App/Handler.ashx?DoType=EmpFull&Key=@Key </font></li>
                <li> @Key 就是指选择的主键. 是系统约定的标记. </li>
            </ul>
            <legend> 该表单的字段 </legend>

            <div id="FrmFileds"></div>
        </fieldset>

    </form>
</body>
</html>
